package com.wakala.employment.fragment.profile;

import static com.xuexiang.xui.utils.XToastUtils.toast;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.vlayout.layout.LinearLayoutHelper;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.github.gzuliyujiang.wheelpicker.OptionPicker;
import com.github.gzuliyujiang.wheelpicker.contract.OnNumberSelectedListener;
import com.github.gzuliyujiang.wheelpicker.contract.OnOptionPickedListener;
import com.github.gzuliyujiang.wheelpicker.contract.OnOptionSelectedListener;
import com.github.gzuliyujiang.wheelpicker.widget.NumberWheelLayout;
import com.github.gzuliyujiang.wheelpicker.widget.OptionWheelLayout;
import com.github.gzuliyujiang.wheelview.annotation.CurtainCorner;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.hjq.toast.Toaster;
import com.kongzue.dialogx.dialogs.BottomMenu;
import com.kongzue.dialogx.dialogs.CustomDialog;
import com.kongzue.dialogx.dialogs.FullScreenDialog;
import com.kongzue.dialogx.dialogs.InputDialog;
import com.kongzue.dialogx.interfaces.OnBindView;
import com.kongzue.dialogx.interfaces.OnInputDialogButtonClickListener;
import com.kongzue.dialogx.interfaces.OnMenuButtonClickListener;
import com.kongzue.dialogx.interfaces.OnMenuItemSelectListener;
import com.lljjcoder.Interface.OnCityItemClickListener;
import com.lljjcoder.bean.CityBean;
import com.lljjcoder.bean.DistrictBean;
import com.lljjcoder.bean.ProvinceBean;
import com.lljjcoder.style.cityjd.JDCityConfig;
import com.lljjcoder.style.cityjd.JDCityPicker;
import com.wakala.employment.R;
import com.wakala.employment.adapter.base.FlowTagAdapter;
import com.wakala.employment.adapter.base.delegate.SimpleDelegateAdapter;
import com.wakala.employment.adapter.bean.OptionBean;
import com.wakala.employment.adapter.entity.NewInfo;
import com.wakala.employment.adapter.jobCategory.CategoryConfigInfo;
import com.wakala.employment.adapter.jobCategory.JobCategoryTreeVo;
import com.wakala.employment.core.BaseFragment;
import com.wakala.employment.core.http.subscriber.NoTipRequestSubscriber;
import com.wakala.employment.databinding.FragmentResumeBinding;
import com.wakala.employment.fragment.finder.JobCategoryAttrFragment;
import com.wakala.employment.fragment.finder.JobCategoryFragment;
import com.wakala.employment.http.TestApi;
import com.wakala.employment.http.bean.ResumeInfoRequest;
import com.wakala.employment.http.bean.ResumeInfoVo;
import com.wakala.employment.http.bean.ResumeJobCategoryRequest;
import com.wakala.employment.utils.TokenUtils;
import com.wakala.employment.utils.Utils;
import com.xuexiang.xhttp2.XHttpProxy;
import com.xuexiang.xhttp2.exception.ApiException;
import com.xuexiang.xhttp2.model.ApiResult;
import com.xuexiang.xpage.annotation.Page;
import com.xuexiang.xpage.enums.CoreAnim;
import com.xuexiang.xpage.utils.GsonUtils;
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder;
import com.xuexiang.xui.adapter.simple.AdapterItem;
import com.xuexiang.xui.utils.CollectionUtils;
import com.xuexiang.xui.utils.ResUtils;
import com.xuexiang.xui.utils.StatusBarUtils;
import com.xuexiang.xui.widget.actionbar.TitleBar;
import com.xuexiang.xui.widget.button.switchbutton.SwitchButton;
import com.xuexiang.xui.widget.flowlayout.FlowTagLayout;
import com.xuexiang.xui.widget.popupwindow.popup.XUISimplePopup;
import com.xuexiang.xui.widget.textview.badge.BadgeView;
import com.xuexiang.xutil.XUtil;
import com.xuexiang.xutil.common.RegexUtils;
import com.xuexiang.xutil.common.StringUtils;
import com.xuexiang.xutil.net.JsonUtil;
import com.xuexiang.xutil.tip.ToastUtils;
import com.zhy.adapter.abslistview.CommonAdapter;
import com.zhy.adapter.abslistview.ViewHolder;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * 个人简历
 * A simple {@link Fragment} subclass.
 * Use the {@link ResumeFragment} factory method to
 * create an instance of this fragment.
 */
@Page(anim = CoreAnim.none)
public class ResumeFragment extends BaseFragment<FragmentResumeBinding> implements View.OnClickListener {

    private static String TAG = ResumeFragment.class.getSimpleName();

    private int selectMenuIndex = 1;

    private ArrayList<String> tagLayoutTags = new ArrayList<>();

    /**
     * 界面多工种配置listView的数据源
     */
    private List<CategoryConfigInfo> categoryConfigList = new ArrayList<>();

    private ListView listView;

    private CommonAdapter<CategoryConfigInfo> listViewAdapter;

    /**
     * ------薪水选择
     */
    private TextView btnCancel, btnSubmit, tvSalaryModeName;
    private FlowTagLayout mSingleFlowTagLayout;
    private LinearLayout llSalaryRange;

    private NumberWheelLayout numSalaryStart, numSalaryEnd;

    /**
     * 薪水模式代码
     */
    private String modeCode = "";
    /**
     * 薪水模式名称
     */
    private String modeName = "";

    /**
     * 薪资范围 起
     */
    private Integer rangeStart = 0;
    /**
     * 薪资范围 至
     */
    private Integer rangeEnd = 0;

    private Map<String, String> modeValueMap = new HashMap<>();
    private Map<Integer, String> modeIndexMap = new HashMap<>();
    private Map<String, Integer> modeResultMap = new HashMap<>();

    private Boolean hasSelectSalaryRang = false;
    //-----------------------------

    /**
     * 自定义加载对话框
     */
    private CustomDialog customDialog = null;//搜索市等待对话框

    private XUISimplePopup mMenuPopup;
    public static AdapterItem[] menuItems = new AdapterItem[]{
            new AdapterItem("登陆", R.drawable.icon_add_user),
            new AdapterItem("筛选", R.drawable.icon_auth1),
            new AdapterItem("设置", R.drawable.icon_setting),
    };

    /**
     * 页面数据绑定对象
     */
    private ResumeInfoVo mResumeInfoVo;
    /**
     * 数据更新对象
     */
    private ResumeInfoRequest mResumeInfoRequest;

    /**
     * 接收工种选择页面返回的选择工种数据
     */
    private List<JobCategoryTreeVo> selectedJobList = new ArrayList<>();
    private Integer currentSelectedJobCategoryId;

    @NonNull
    @Override
    protected FragmentResumeBinding viewBindingInflate(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, boolean attachToRoot) {
        return FragmentResumeBinding.inflate(inflater, container, attachToRoot);
    }


    /**
     * @return 返回为 null意为不需要导航栏
     */
    @Override
    protected TitleBar initTitle() {
        StatusBarUtils.setStatusBarLightMode(getActivity());
        //设置状态栏背景颜色，如果设置为 Color.TRANSPARENT 将会隐藏状态栏
        requireActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.white));
        return null;
    }

    @Override
    protected void initListeners() {
        binding.btnModifyProfile.setOnClickListener(this);//修改个人信息
        binding.ssBtnModifyResume.setOnClickListener(this);
        //binding.stvModifyKind.setOnClickListener(this);
        binding.ivGoBack.setOnClickListener(this);
        binding.tvSwitchFindState.setOnClickListener(this);
        binding.llCityPicker.setOnClickListener(this);
        binding.btnJobLinkPhone.setOnClickListener(this);//联系电话
        binding.tvJobHopeCategory.setOnClickListener(this);//求职意向
        binding.btnSelfIntro.setOnClickListener(this);//个人介绍
        binding.tvWorkYears.setOnClickListener(this);//工作年限
        binding.tvEducation.setOnClickListener(this);//文化程度
        binding.tvMarriage.setOnClickListener(this);//婚姻状况
    }

    @Override
    protected void initViews() {
        binding.progressViewCircleSmall.startProgressAnimation();
        //recyclerView = binding.jobCategoryRecyclerView;
        listView = binding.listview;

        listViewAdapter = new CommonAdapter<CategoryConfigInfo>(getContext(), R.layout.item_resume_job_category, categoryConfigList) {
            @Override
            protected void convert(ViewHolder holder, CategoryConfigInfo item, int i) {
                holder.setText(R.id.tv_job_category_name, item.getJobCategoryName());
                holder.setText(R.id.tv_job_want_salary, item.getSalaryName());
                holder.setText(R.id.tv_job_attr_value, item.getJobCategoryAttrValue());
                //
                holder.setTag(R.id.tv_job_want_salary, item.getJobCategoryId());
                holder.getView(R.id.tv_job_want_salary).setTag(item.getJobCategoryId());
                holder.setTag(R.id.tv_job_attr_value, item.getJobCategoryId());

                holder.setOnClickListener(R.id.tv_job_want_salary, view -> {
                    Object cid = view.getTag();
                    currentSelectedJobCategoryId = Integer.parseInt(cid.toString());
                    //工种-薪水配置
                    showSalarySelect(currentSelectedJobCategoryId);
                });
                holder.setOnClickListener(R.id.tv_job_attr_value, view -> {
                    currentSelectedJobCategoryId = Integer.parseInt(view.getTag().toString());
                    //工种-职业优势配置
                    showJobCategoryAttrConfig(currentSelectedJobCategoryId);
                });
            }
        };
        listView.setAdapter(listViewAdapter);

        //--------薪水选择初始化----------
        modeValueMap.put("R", "日");
        modeValueMap.put("Y", "月");
        modeValueMap.put("J", "件");
        modeValueMap.put("M", "面议");
        //
        modeIndexMap.put(0, "R");
        modeIndexMap.put(1, "Y");
        modeIndexMap.put(2, "J");
        modeIndexMap.put(3, "M");
        //
        modeResultMap.put("M", 0);
        modeResultMap.put("R", 1);
        modeResultMap.put("Y", 2);
        modeResultMap.put("J", 3);
        //-----------------

        new BadgeView(getContext()).bindTarget(binding.ssBtnContinueRefresh)
                .setBadgeGravity(Gravity.CENTER_VERTICAL | Gravity.END)
                .setBadgeText("折扣");

        binding.sbFindState.setOnClickListener(this);
        binding.sbFindState.setChecked(true);
        initMenuPopup();
        initCustomDialog();
        //请求简历数据
        getUserResumeInfo();
    }

    /**
     * 初始化加载对话框
     */
    private void initCustomDialog() {
        //初始化加载等待对话框
        customDialog = CustomDialog.build()
                .setCustomView(new OnBindView<CustomDialog>(R.layout.dialog_layout_spinkit) {
                    @Override
                    public void onBind(final CustomDialog dialog, View v) {
                      /*  ImageView btnOk;
                        btnOk = v.findViewById(R.id.btn_ok);
                        btnOk.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                dialog.dismiss();
                            }
                        });*/
                    }
                });
    }

    private void initMenuPopup() {
        mMenuPopup = new XUISimplePopup(getContext(), menuItems)
                .create((adapter, item, position) -> toast(item.getTitle().toString()));
    }

    @Override
    public void onFragmentResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == 100) {
            //List
            //选择工种分类
            tagLayoutTags = data.getStringArrayListExtra("tagLayoutTags");
            selectedJobList = data.getParcelableArrayListExtra("selectedJobList");
            String kindText = "";
            String jobCategoryIds = "";
            List<CategoryConfigInfo> tempList = new ArrayList<>();
            for (JobCategoryTreeVo jobCategoryTreeVo : selectedJobList) {
                kindText += jobCategoryTreeVo.getName() + "、";
                tempList.add(new CategoryConfigInfo(jobCategoryTreeVo.getId(), jobCategoryTreeVo.getName(), "请选择", "请选择"));
                //
                jobCategoryIds += jobCategoryTreeVo.getId() + ",";
            }
           /* for (String tagText : tagLayoutTags) {
                kindText += tagText + "、";
                //
                tempList.add(new CategoryConfigInfo(tagText,"请选择","请选择"));
            }*/
            if (!StringUtils.isEmpty(kindText)) {
                kindText = StringUtils.cutString(kindText, 0, kindText.length() - 1);
                binding.tvJobHopeCategory.setText(kindText);
            }

            if (!StringUtils.isEmpty(jobCategoryIds)) {
                initResumeRequest();
                mResumeInfoRequest.setJobCategory(jobCategoryIds);
                updateUserResumeInfo(mResumeInfoRequest);
            }

            //
            if (!tempList.isEmpty()) {
                XUtil.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        categoryConfigList.clear();
                        categoryConfigList.addAll(tempList);
                        listViewAdapter.notifyDataSetChanged();
                    }
                });
            }


        } else if (resultCode == 101) {
            //修改个人介绍
            String introText = data.getStringExtra("introText");
            binding.tvSelfIntro.setText(introText);
            initResumeRequest();
            mResumeInfoRequest.setIntroduce(introText);
            updateUserResumeInfo(mResumeInfoRequest);
        } else if (resultCode == 102) {
            //返回工种-》职业优势配置

        }
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.sb_find_state) {
            view = (com.xuexiang.xui.widget.button.switchbutton.SwitchButton) view;
            if (((SwitchButton) view).isChecked()) {
                binding.tvFindStateText.setText("找活中");
            } else {
                binding.tvFindStateText.setText("暂停找活");
            }

        } else if (id == R.id.btn_modify_profile) {
            //修改个人信息
            openNewPage(ProfileFragment.class);
        } else if (id == R.id.ssBtn_modify_resume) {
            openNewPage(BasicsInfoFragment.class);
        } else if (id == R.id.stv_modify_kind) {

        } else if (id == R.id.iv_go_back) {
            popToBack();
        } else if (id == R.id.tv_switch_find_state) {
            //切换找活状态，弹出底部菜单
            switchFindState();
        } else if (id == R.id.ll_city_picker) {
            //求职意向-城市选择
            showCityPicker();
        } else if (id == R.id.tv_job_hope_category) {
            //求职意向-工种
            //openNewPage(FindJobInfoFragment.class);
            //openPageForResult(FindJobInfoFragment.class,100);
            openPageForResult(JobCategoryFragment.class, 100);
        } else if (id == R.id.btn_job_link_phone) {
            showBindPhoneNumber();
        } else if (id == R.id.btn_self_intro) {
            //openNewPage(SelfIntroductionFragment.class);
            openPageForResult(SelfIntroductionFragment.class, 101);
        } else if (id == R.id.tv_work_years) {
            //工作年限
            showWorkYears();
        } else if (id == R.id.tv_education) {
            showEducation();
        } else if (id == R.id.tv_marriage) {
            showMarriage();
        }

    }

    /**
     * 新婚姻状态
     */
    private void showMarriage() {
        List<OptionBean> data = new ArrayList<>();
        data.add(new OptionBean("0", "未婚"));
        data.add(new OptionBean("1", "已婚"));
        data.add(new OptionBean("2", "保密"));

        OptionPicker picker = new OptionPicker(getActivity());
        picker.setTitle("婚姻状况");
        picker.setBodyWidth(140);
        picker.setData(data);
        picker.setDefaultPosition(1);
        picker.setOnOptionPickedListener(new OnOptionPickedListener() {
            @Override
            public void onOptionPicked(int position, Object item) {
                //toast(item.toString());
                binding.tvMarriage.setText(item.toString());
                //更新婚姻状态
                OptionBean optionBean = (OptionBean) item;
                initResumeRequest();
                mResumeInfoRequest.setMarriageStatus(optionBean.getId());
                updateUserResumeInfo(mResumeInfoRequest);
            }
        });
        picker.show();
    }

    /**
     * 文化程序
     */
    private void showEducation() {
        List<OptionBean> data = new ArrayList<>();
        data.add(new OptionBean("0", "初、高中"));
        data.add(new OptionBean("1", "中专、职业技校"));
        data.add(new OptionBean("2", "大学专科"));
        data.add(new OptionBean("3", "大学本科"));
        data.add(new OptionBean("4", "硕士"));
        data.add(new OptionBean("5", "博士"));

        OptionPicker picker = new OptionPicker(getActivity());
        picker.setTitle("文化程度");
        picker.setBodyWidth(140);
        picker.setData(data);
        picker.setDefaultPosition(2);
        picker.setOnOptionPickedListener(new OnOptionPickedListener() {
            @Override
            public void onOptionPicked(int position, Object item) {
                //toast(item.toString());
                binding.tvEducation.setText(item.toString());
                //更新学历文化程度
                OptionBean optionBean = (OptionBean) item;
                initResumeRequest();
                mResumeInfoRequest.setEducation(optionBean.getId());
                updateUserResumeInfo(mResumeInfoRequest);
            }
        });
        picker.show();
    }

    /**
     * 工作年限
     */
    private void showWorkYears() {
        List<OptionBean> data = new ArrayList<>();
        data.add(new OptionBean("0", "0-1年"));
        data.add(new OptionBean("1", "1-3年"));
        data.add(new OptionBean("2", "3-5年"));
        data.add(new OptionBean("3", "5-7年"));
        data.add(new OptionBean("4", "7-10年"));
        data.add(new OptionBean("5", "10-15年"));
        data.add(new OptionBean("6", "15-20年"));
        data.add(new OptionBean("7", "20年以上"));

        OptionPicker picker = new OptionPicker(getActivity());
        picker.setTitle("工作年限");
        picker.setBodyWidth(140);
        picker.setData(data);
        picker.setDefaultPosition(1);
        picker.setOnOptionPickedListener(new OnOptionPickedListener() {
            @Override
            public void onOptionPicked(int position, Object item) {
                //toast(item.toString());
                binding.tvWorkYears.setText(item.toString());
                //更新工作年限
                OptionBean optionBean = (OptionBean) item;
                initResumeRequest();
                mResumeInfoRequest.setWorkYears(optionBean.getId());
                updateUserResumeInfo(mResumeInfoRequest);
            }
        });
        OptionWheelLayout wheelLayout = picker.getWheelLayout();
        //wheelLayout.setIndicatorEnabled(false);
//        wheelLayout.setTextColor(0xFFFF00FF);
//        wheelLayout.setSelectedTextColor(0xFFFF0000);
//        wheelLayout.setTextSize(15 * getResources().getDisplayMetrics().scaledDensity);
        wheelLayout.setSelectedTextBold(true);
//        wheelLayout.setCurtainEnabled(true);
//        wheelLayout.setCurtainColor(0xEEFF0000);
//        wheelLayout.setCurtainCorner(CurtainCorner.ALL);
//        wheelLayout.setCurtainRadius(5 * getResources().getDisplayMetrics().density);
        wheelLayout.setOnOptionSelectedListener(new OnOptionSelectedListener() {
            @Override
            public void onOptionSelected(int position, Object item) {
                picker.getTitleView().setText(picker.getWheelView().formatItem(position));
            }
        });
        picker.show();
    }

    /**
     * 修改联系电话
     */
    private void showBindPhoneNumber() {
        String preInputText = binding.tvJobLinkPhone.getText().toString();
        new InputDialog("系统提示", "请输入正确的手机号码", "确定", "取消", preInputText)
                .setCancelable(false)
                .setOkButton(new OnInputDialogButtonClickListener<InputDialog>() {
                    @Override
                    public boolean onClick(InputDialog baseDialog, View v, String inputStr) {
                        if (RegexUtils.isMobileExact(inputStr)) {
                            binding.tvJobLinkPhone.setText(inputStr);
                            baseDialog.dismiss();
                            //更新简历联系电话
                            initResumeRequest();
                            mResumeInfoRequest.setJobLinkPhone(inputStr);
                            updateUserResumeInfo(mResumeInfoRequest);
                        } else {
                            Toaster.show("输入的手机号码不正确");
                        }
                        return true;
                    }
                })
                .show();
    }

    private void showCityPicker() {
        //创建对象
        JDCityPicker cityPicker = new JDCityPicker();
        //初始化配置
        JDCityConfig jdCityConfig = new JDCityConfig.Builder().build();
        //设置显示的样式
        jdCityConfig.setShowType(JDCityConfig.ShowType.PRO_CITY);
        cityPicker.init(getContext());//初始化选择器
        cityPicker.setConfig(jdCityConfig);
        cityPicker.setOnCityItemClickListener(new OnCityItemClickListener() {
            @Override
            public void onSelected(ProvinceBean province,
                                   CityBean city, DistrictBean district) {//选中后的监听
               /* binding.tvWantCity.setText("城市选择结果：\n" +
                        province.getName() + "(" + province.getId() + ")\n"
                        + city.getName() + "(" + city.getId() + ")\n"
                        + district.getName() + "(" + district.getId() + ")");*/
                String cityName = city.getName();
                if (city.getName().equals("市辖区")) {
                    cityName = province.getName();
                }
                binding.tvWantCity.setText(cityName);
                //更新求职意向 城市
                initResumeRequest();
                mResumeInfoRequest.setJobCity(cityName);
                updateUserResumeInfo(mResumeInfoRequest);
            }

            @Override
            public void onCancel() {
                //cancel监听
            }
        });
        //显示地区列表
        cityPicker.showCityPicker();
    }

    private void switchFindState() {

        List<String> menus = new ArrayList<>();
        menus.add("暂不找活");
        menus.add("随时到岗");
        menus.add("月内到岗");
        menus.add("考虑机会");


        BottomMenu.show(new String[]{"随时到岗", "月内到岗", "考虑机会", "暂不找活"})
                .setMessage("找活状态会影响被推荐的几率，以及影响老板的决定")
                .setTitle("找活状态").setCancelable(false).setCancelButton("确定", new OnMenuButtonClickListener<BottomMenu>() {
                    @Override
                    public boolean onClick(BottomMenu baseDialog, View v) {
                        return false;
                    }
                })
                .setOnMenuItemClickListener(new OnMenuItemSelectListener<BottomMenu>() {
                    @Override
                    public boolean onClick(BottomMenu dialog, CharSequence text, int index) {
                        //记录已选择值
                        selectMenuIndex = index;
                        toast(text);
                        binding.tvSwitchFindState.setText(text);
                        return true;
                    }
                })
                .setSelection(selectMenuIndex);        //指定已选择的位置
    }

    @SuppressLint("CheckResult")
    private void getUserResumeInfo() {
        binding.llStateful.showLoading();
        XHttpProxy.proxy(TestApi.IResumeService.class)
                .getUserResumeInfo()
                .subscribeWith(new NoTipRequestSubscriber<ResumeInfoVo>() {
                    @Override
                    protected void onSuccess(ResumeInfoVo resumeInfoVo) {
                        Log.i(TAG, "-------------招工信息详情------------------");
                        Log.i(TAG, GsonUtils.toJson(resumeInfoVo));
                        mResumeInfoVo = resumeInfoVo;
                        Log.i(TAG, "-------------招工信息详情------------------");
                        //绑定数据到页面控件
                        bindData(mResumeInfoVo);
                        binding.llStateful.showContent();
                    }

                    @Override
                    public void onError(ApiException e) {
                        super.onError(e);
                        ToastUtils.toast(e.getDisplayMessage());
                        Log.i(TAG, "-------------招工信息详情-返回错误------------------");
                        Log.e(TAG, e.getMessage());
                        binding.llStateful.showError("请求数据失败" + e.getDisplayMessage(), "重试", new View.OnClickListener() {
                            @Override
                            public void onClick(View view) {
                                getUserResumeInfo();
                            }
                        });
                    }

                });
    }

    @SuppressLint("CheckResult")
    private void updateUserResumeInfo(ResumeInfoRequest resumeInfoRequest) {
        customDialog.show();
        XHttpProxy.proxy(TestApi.IResumeService.class)
                .updateUserResume(resumeInfoRequest)
                .subscribeWith(new NoTipRequestSubscriber() {

                    @Override
                    protected void onSuccess(Object o) {
                        Log.i(TAG, "-------------更新简历信息详情------------------");
                        customDialog.dismiss();
                        getUserResumeInfo();
                        Toaster.show("修改成功");
                        Log.i(TAG, "-------------更新简历信息详情------------------");
                    }

                    @Override
                    public void onError(ApiException e) {
                        super.onError(e);
                        customDialog.dismiss();
                        ToastUtils.toast(e.getDisplayMessage());
                        Log.i(TAG, "-------------更新简历信息详情-返回错误------------------");
                        Log.e(TAG, e.getMessage());
                    }

                });
    }

    private void initResumeRequest() {
        mResumeInfoRequest = null;
        mResumeInfoRequest = new ResumeInfoRequest();
        mResumeInfoRequest.setId(mResumeInfoVo.getId());
        mResumeInfoRequest.setUid(mResumeInfoVo.getUid());
        mResumeInfoRequest.setResumeNo(mResumeInfoVo.getResumeNo());
    }

    /**
     * 更新工种薪资配置
     *
     * @param resumeJobCategoryRequest
     */
    @SuppressLint("CheckResult")
    private void updateUserResumeJobCategorySalary(ResumeJobCategoryRequest resumeJobCategoryRequest) {
        customDialog.show();
        XHttpProxy.proxy(TestApi.IResumeService.class)
                .updateUserResumeJobCategorySalary(resumeJobCategoryRequest)
                .subscribeWith(new NoTipRequestSubscriber() {

                    @Override
                    protected void onSuccess(Object o) {
                        Log.i(TAG, "-------------更新简历信息详情------------------");
                        customDialog.dismiss();
                        getUserResumeInfo();
                        Toaster.show("修改成功");
                        Log.i(TAG, "-------------更新简历信息详情------------------");
                    }

                    @Override
                    public void onError(ApiException e) {
                        super.onError(e);
                        customDialog.dismiss();
                        ToastUtils.toast(e.getDisplayMessage());
                        Log.i(TAG, "-------------更新简历信息详情-返回错误------------------");
                        Log.e(TAG, e.getMessage());
                    }

                });
    }

    /**
     * 界面控件数据绑定
     *
     * @param mResumeInfoVo
     */
    private void bindData(ResumeInfoVo mResumeInfoVo) {
        String s = JsonUtil.toJson(mResumeInfoVo);
        //头像
        if (Utils.isHttpAddress(mResumeInfoVo.getAvatar())) {
            // Uri uri = Uri.parse(user.getAvatar());
            // binding.rivHeadPic.setImageURI(uri);
            RequestOptions options = new RequestOptions()
                    .centerCrop()
                    .placeholder(R.color.color_f4)
                    .diskCacheStrategy(DiskCacheStrategy.ALL);
            Glide.with(binding.tvUserAvatar.getContext()).load(mResumeInfoVo.getAvatar())
                    .apply(options)
                    .into(binding.tvUserAvatar);
        }
        binding.tvNikeName.setText(mResumeInfoVo.getNickname());//修改个人信息
        if (mResumeInfoVo.getAge() == 0) {
            binding.tvUserAge.setText("年龄保密");//年龄
        } else {
            binding.tvUserAge.setText(mResumeInfoVo.getAge() + "岁");//年龄
        }
        binding.tvUserNation.setText(mResumeInfoVo.getNation());//民族
        binding.tvUserIpRegion.setText(mResumeInfoVo.getIpRegion());//IP归属地
        binding.tvJobLinkPhone.setText(mResumeInfoVo.getJobLinkPhone());//简历联系电话
        binding.tvJobHopeCategory.setText(mResumeInfoVo.getJobCategory());//求职意向
        try {
            binding.tvSelfIntro.setText(mResumeInfoVo.getIntroduce());//个人介绍
        } catch (Exception e) {
            e.printStackTrace();
        }
        binding.tvWorkYears.setText(mResumeInfoVo.getWorkYearsName());//工作年限
        binding.tvEducation.setText(mResumeInfoVo.getEducationName());//文化程度
        binding.tvMarriage.setText(mResumeInfoVo.getMarriageStatusName());//婚姻状况
        binding.tvSwitchFindState.setText(mResumeInfoVo.getJobStateName());//求职状态
        binding.tvJobHopeCategory.setText(mResumeInfoVo.getJobCategoryName());//求职意向职位
        binding.tvWantCity.setText(mResumeInfoVo.getJobCityName());//求职意向 城市
        //实名认证展示
        if (mResumeInfoVo.getRealNameAuth()) {
            binding.tvIsRealNameAuthed.setVisibility(View.VISIBLE);
        } else binding.tvIsRealNameAuthed.setVisibility(View.GONE);
        //绑定职业偏好
        if (!CollectionUtils.isEmpty(mResumeInfoVo.getCategoryConfigInfoList())) {
            categoryConfigList.clear();
            categoryConfigList.addAll(mResumeInfoVo.getCategoryConfigInfoList());
            listViewAdapter.notifyDataSetChanged();
        }


    }

    /**
     * -----薪水选额相关组件---------------------------------
     */
    private void initSingleFlowTagLayout() {
        FlowTagAdapter tagAdapter = new FlowTagAdapter(getContext());
        mSingleFlowTagLayout.setAdapter(tagAdapter);
        mSingleFlowTagLayout.setTagCheckedMode(FlowTagLayout.FLOW_TAG_CHECKED_SINGLE);
        mSingleFlowTagLayout.setOnTagSelectListener((parent, position, selectedList) -> DoOnTagSelect(parent, position, selectedList));
        tagAdapter.addTags(ResUtils.getStringArray(getContext(), R.array.tags_values));
        tagAdapter.setSelectedPositions(0);

    }

    private String DoOnTagSelect(FlowTagLayout parent, int position, List<Integer> selectedList) {
        StringBuilder sb = new StringBuilder("选中的内容：\n");
        for (int index : selectedList) {
            sb.append(parent.getAdapter().getItem(index));
            sb.append(";");
        }
        if (3 == position) {
            llSalaryRange.setVisibility(View.GONE);
        } else {
            llSalaryRange.setVisibility(View.VISIBLE);
        }
        initNumSalaryPicker(position);
        getSalaryUnitStr(position);
        return sb.toString();
    }

    /**
     * 薪水范围选贼器 数据选中事件绑定
     */
    private void bindEventSalaryPicker() {
        numSalaryStart.setOnNumberSelectedListener(new OnNumberSelectedListener() {
            @Override
            public void onNumberSelected(int position, Number item) {
                rangeStart = item.intValue();
                //设置薪水返回已经选择过
                hasSelectSalaryRang = true;
            }
        });
        numSalaryEnd.setOnNumberSelectedListener(new OnNumberSelectedListener() {
            @Override
            public void onNumberSelected(int position, Number item) {
                rangeEnd = item.intValue();
            }
        });
    }

    private void initNumSalaryPicker(Integer jieSuanFS) {
        if (null == jieSuanFS) {
            jieSuanFS = 0;
        }
        if (jieSuanFS == 0) {
            //日结
            numSalaryStart.setRange(100, 2000, 100);
            numSalaryEnd.setRange(200, 2100, 100);
            //初始化选择器的选值
            rangeStart = 100;
            rangeEnd = 200;
        } else if (jieSuanFS == 1) {
            //月结
            numSalaryStart.setRange(1000, 290000, 1000);
            numSalaryEnd.setRange(2000, 300000, 1000);
            //初始化选择器的选值
            rangeStart = 1000;
            rangeEnd = 2000;
        } else if (jieSuanFS == 2) {
            //计量
            numSalaryStart.setRange(1, 490, 10);
            numSalaryEnd.setRange(10, 500, 10);
            //初始化选择器的选值
            rangeStart = 1;
            rangeEnd = 10;
        }
    }

    private String getSalaryUnitStr(Integer unitIndex) {
        String pre = "单位：元/";
        if (3 == unitIndex) {
            pre = "";
        }
        modeCode = modeIndexMap.get(unitIndex);
        modeName = modeValueMap.get(modeIndexMap.get(unitIndex));
        tvSalaryModeName.setText(pre + modeName);
        return pre + modeName;
    }

    private void showSalarySelect(Integer selectedJobCategoryId) {
        /**
         * 采用异步加载布局防止卡顿测试
         */

        OnBindView<FullScreenDialog> onBindView;
        onBindView = new OnBindView<FullScreenDialog>(R.layout.layout_dialog_salary, false) {
            @Override
            public void onBind(FullScreenDialog dialog, View v) {
                btnCancel = v.findViewById(R.id.btn_cancel);
                btnSubmit = v.findViewById(R.id.btn_submit);
                tvSalaryModeName = v.findViewById(R.id.tv_salary_mode_name);
                mSingleFlowTagLayout = v.findViewById(R.id.flowlayout_single_select);
                llSalaryRange = v.findViewById(R.id.ll_salary_range);
                initSingleFlowTagLayout();
                numSalaryStart = v.findViewById(R.id.num_salary_start);
                numSalaryEnd = v.findViewById(R.id.num_salary_end);
                initNumSalaryPicker(0);
                bindEventSalaryPicker();
                getSalaryUnitStr(0);
                //初始化并显示期望薪资设置组件
                initFullScreenLoginDemo(dialog, selectedJobCategoryId);
            }
        };
        FullScreenDialog.show(onBindView);
    }

    /**
     * 初始化并显示期望薪资设置组件
     *
     * @param fullScreenDialog
     * @param selectedJobCategoryId
     */
    private void initFullScreenLoginDemo(final FullScreenDialog fullScreenDialog, Integer selectedJobCategoryId) {
        btnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                fullScreenDialog.dismiss();
            }
        });

        btnCancel.setText("取消");
        btnSubmit.setText("确定");

        btnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (rangeStart >= rangeEnd && !modeCode.equals("M")) {
                    Toaster.show("薪资范围选择错误，起始薪资大于结束薪资");
                } else {
                    fullScreenDialog.dismiss();
                    Toaster.show(rangeStart + "-" + rangeEnd + "元/" + modeName);
                    String salaryName = "";
                    if (modeCode.equals("M")) {
                        //binding.stvJobSalary.setCenterString(modeName);
                        salaryName = modeName;
                    } else {
                        //binding.stvJobSalary.setCenterString(rangeStart+"-"+rangeEnd+"元/"+modeName);
                        salaryName += rangeStart + "-" + rangeEnd + "元/" + modeName;
                    }

                    //更新ListView数据源，刷新界面数据绑定
                    updateCategoryConfigListSalary(salaryName, selectedJobCategoryId);
                    //更新服务器数据
                    ResumeJobCategoryRequest resumeJobCategoryRequest = new ResumeJobCategoryRequest();
                    resumeJobCategoryRequest.setJobCategoryId(selectedJobCategoryId);
                    resumeJobCategoryRequest.setSalaryMode(modeResultMap.get(modeCode));
                    resumeJobCategoryRequest.setResumeId(mResumeInfoVo.getId());
                    resumeJobCategoryRequest.setSalaryUnit(1);
                    resumeJobCategoryRequest.setSalaryStart(rangeStart);
                    resumeJobCategoryRequest.setSalaryEnd(rangeEnd);
                    //调用接口，更新服务器数据
                    updateUserResumeJobCategorySalary(resumeJobCategoryRequest);

                }

            }
        });
    }

    //----------------------------------------
    private void updateCategoryConfigListSalary(String salaryName, Integer selectedJobCategoryId) {
        categoryConfigList.stream().forEach(item -> {
            if (item.getJobCategoryId().intValue() == selectedJobCategoryId.intValue()) {
                item.setSalaryName(salaryName);
            }
        });
        XUtil.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                //categoryConfigList.clear();
                //categoryConfigList.addAll(tempList);
                listViewAdapter.notifyDataSetChanged();
            }
        });
    }
    //--------------------------------

    private void showJobCategoryAttrConfig(Integer selectedJobCategoryId) {
        openPageForResult(JobCategoryAttrFragment.class, "cid", selectedJobCategoryId, 102);
    }
}